local boweimu = fk.CreateSkill {
    name = "boweimu",
    tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
    ["boweimu"] = "帷幕",
    [":boweimu"] = "锁定技，游戏开始时为其他角色各添加2个「乱」标记，<br>每轮开始时再添加1个；所有人距离-2。<br>当你受到非属性伤害时，防止此伤害。",
    ["$boweimu1"] = "想伤我？没那么容易！",
    ["$boweimu2"] = "我就看看，不说话。",
}

-- 游戏开始初始化标记（2个）
boweimu:addEffect(fk.GameStart, {
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(boweimu.name)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local targets = room:getOtherPlayers(player)
        for _, p in ipairs(targets) do
            room:setPlayerMark(p, "@bianxi_dun", 0)
            room:addPlayerMark(p, "@bianxi_dun", 2)
        end
        room.boweimu_round = 1
    end,
})

-- 每轮开始时添加1个标记
boweimu:addEffect(fk.RoundStart, {
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(boweimu.name) and player.room.boweimu_round
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local targets = room:getOtherPlayers(player)
        for _, p in ipairs(targets) do
            room:addPlayerMark(p, "@bianxi_dun", 1)
        end
        room.boweimu_round = room.boweimu_round + 1
    end,
})

-- 距离修正：所有人距离-2
boweimu:addEffect("distance", {
    correct_func = function(self, from, to)
        if from ~= to then
            return -2  -- 距离减少2
        end
        return 0
    end,
})

-- 防止非属性伤害
boweimu:addEffect(fk.DamageInflicted, {
    anim_type = "defensive",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(boweimu.name) and
               data.damageType == fk.NormalDamage
    end,
    on_use = function(self, event, target, player, data)
        data:preventDamage()
    end,
})

return boweimu
